package net.towee.server.test.managers;

import java.util.List;
import java.util.Map;

import net.towee.model.account.AccountData;
import net.towee.model.account.AccountGroup;
import net.towee.model.account.AccountIdentity;
import net.towee.model.account.AccountProfile;
import net.towee.model.account.Board;
import net.towee.model.account.ContactsGroup;
import net.towee.model.account.Gadget;
import net.towee.model.account.Role;
import net.towee.model.discussion.Discussion;
import net.towee.model.discussion.DiscussionSubject;
import net.towee.model.discussion.Message;
import net.towee.model.group.GroupData;
import net.towee.model.group.GroupEnterRequest;
import net.towee.model.group.GroupIdentity;
import net.towee.model.group.GroupProfile;
import net.towee.model.repo.AttachmentIdentity;
import net.towee.model.repo.AttachmentInfo;
import net.towee.model.repo.DocumentData;
import net.towee.model.repo.DocumentIdentity;
import net.towee.model.repo.DocumentPatch;
import net.towee.model.repo.DocumentType;
import net.towee.model.repo.NodeData;
import net.towee.model.utils.Pair;
import net.towee.server.rpc.services.ToweeServiceAsync;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;

/**
 * Implementation of async service. It simply wrap to sync methods
 * on server side.
 * @author c58
 */
public class ToweeServiceAsyncTestImpl implements ToweeServiceAsync {
	private final ToweeTestService service;
	
	@Inject
	public ToweeServiceAsyncTestImpl(ToweeTestService service) {
		this.service = service;
	}
	
	public ToweeTestService getService() {
		return service;
	}
	
	@Override
	public void getCurrentAccount(AsyncCallback<AccountData> asyncCallback) {
		try {
			asyncCallback.onSuccess(service.getCurrentAccount());
		} catch (Exception e) {
			asyncCallback.onFailure(e);
		}
	}

	@Override
	public void getAccountProfile(String accountId, AsyncCallback<AccountProfile> asyncCallback) {
		try {
			asyncCallback.onSuccess(service.getAccountProfile(accountId));
		} catch (Exception e) {
			asyncCallback.onFailure(e);
		}
	}

	@Override
	public void getAccountIdentity(String accountId, AsyncCallback<AccountIdentity> asyncCallback) {
		try {
			asyncCallback.onSuccess(service.getAccountIdentity(accountId));
		} catch (Exception e) {
			asyncCallback.onFailure(e);
		}
	}

	@Override
	public void checkAccountWithNicknameExists(String nickname, AsyncCallback<Boolean> asyncCallback) {
		try {
			asyncCallback.onSuccess(service.checkAccountWithNicknameExists(nickname));
		} catch (Exception e) {
			asyncCallback.onFailure(e);
		}
	}

	@Override
	public void updateAccountIdentity(AccountIdentity identity, AsyncCallback<Boolean> asyncCallback) {
		try {
			asyncCallback.onSuccess(service.updateAccountIdentity(identity));
		} catch (Exception e) {
			asyncCallback.onFailure(e);
		}
	}

	@Override
	public void updateAccountProfile(AccountProfile profile, AsyncCallback<Boolean> asyncCallback) {
		try {
			asyncCallback.onSuccess(service.updateAccountProfile(profile));
		} catch (Exception e) {
			asyncCallback.onFailure(e);
		}
	}

	@Override
	public void putSetting(String key, String val, AsyncCallback<Boolean> asyncCallback) {
		try {
			asyncCallback.onSuccess(service.putSetting(key, val));
		} catch (Exception e) {
			asyncCallback.onFailure(e);
		}
	}

	@Override
	public void updateSettings(Map<String, String> settingsMap, AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.updateSettings(settingsMap));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void onAccountIdentityUpdated(AccountIdentity result, String node,
			AsyncCallback<AccountIdentity> asyncCallback) {
	}

	@Override
	public void onAccountProfileUpdated(AccountProfile result, String node,
			AsyncCallback<AccountProfile> asyncCallback) {
	}

	@Override
	public void onOnlineStateChanged(Pair<String, Boolean> result, String node,
			AsyncCallback<Pair<String, Boolean>> asyncCallback) {
	}

	@Override
	public void createAttachmentIdentity(String rawAttachmentId, AsyncCallback<AttachmentIdentity> handler) {
		try {
			handler.onSuccess(service.createAttachmentIdentity(rawAttachmentId));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void getAttachmentInfo(String attachmentId, AsyncCallback<AttachmentInfo> asyncCallback) {
		try {
			asyncCallback.onSuccess(service.getAttachmentInfo(attachmentId));
		} catch (Exception e) {
			asyncCallback.onFailure(e);
		}
	}

	@Override
	public void onUserAddedToContacts(Pair<AccountIdentity, String> result, String node,
			AsyncCallback<Pair<AccountIdentity, String>> asyncCallback) {
	}

	@Override
	public void onUserRemovedFromContacts(Pair<AccountIdentity, String> result, String node,
			AsyncCallback<Pair<AccountIdentity, String>> asyncCallback) {
	}

	@Override
	public void createContactsGroup(String name, AsyncCallback<ContactsGroup> handler) {
		try {
			handler.onSuccess(service.createContactsGroup(name));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void removeContactsGroup(String id, AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.removeContactsGroup(id));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void renameContactsGroup(String id, String newName, AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.renameContactsGroup(id, newName));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void addContactsToGroup(String id, List<AccountIdentity> accounts,
			AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.addContactsToGroup(id, accounts));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void removeContactsForomGroup(String id, List<String> accountIds,
			AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.removeContactsForomGroup(id, accountIds));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void addBoard(Board board, AsyncCallback<Board> asyncCallback) {
		try {
			asyncCallback.onSuccess(service.addBoard(board));
		} catch (Exception e) {
			asyncCallback.onFailure(e);
		}
	}

	@Override
	public void removeBoard(String boardId, AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.removeBoard(boardId));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void renameBoard(String boardId, String newName, AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.renameBoard(boardId, newName));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void attachGroupToBoard(String boardId, String groupId, AsyncCallback<GroupIdentity> handler) {
		try {
			handler.onSuccess(service.attachGroupToBoard(boardId, groupId));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void detachGroupFromBoard(String boardId, String groupId, AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.detachGroupFromBoard(boardId, groupId));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void getDiscussion(String id, DiscussionSubject subject, int offset, int limit, AsyncCallback<Discussion> handler) {
		try {
			handler.onSuccess(service.getDiscussion(id, subject, offset, limit));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void onDiscussionMessageUpdate(Pair<String, Message> result, String node,
			AsyncCallback<Pair<String, Message>> asyncCallback) {
	}

	@Override
	public void addDiscussionMessage(String discId, DiscussionSubject subject, Message mess, AsyncCallback<String> handler) {
		try {
			handler.onSuccess(service.addDiscussionMessage(discId, subject, mess));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void changeDiscussionMessage(String discId, DiscussionSubject subject, Message mess, AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.changeDiscussionMessage(discId, subject, mess));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void onDocumentUpdate(DocumentData doc, String node, AsyncCallback<DocumentData> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onDocumentDelete(List<DocumentIdentity> identity, String node,
			AsyncCallback<List<DocumentIdentity>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onDocumentRated(Pair<AccountIdentity, DocumentIdentity> result, String node,
			AsyncCallback<Pair<AccountIdentity, DocumentIdentity>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getDocuments(String docId, AsyncCallback<DocumentData> handler) {
		try {
			handler.onSuccess(service.getDocuments(docId));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void saveDocument(DocumentData doc, String parentNodeId, AsyncCallback<DocumentData> handler) {
		try {
			handler.onSuccess(service.saveDocument(doc, parentNodeId));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void changeDocument(DocumentData doc, String explain, AsyncCallback<DocumentData> handler) {
		try {
			handler.onSuccess(service.changeDocument(doc, explain));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void tupDocument(String docId, AsyncCallback<Boolean> handler) {
		try {
			handler.onSuccess(service.tupDocument(docId));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void getDocumentPatchs(List<String> neededPatchs,
			AsyncCallback<Map<String, DocumentPatch>> handler) {
		try {
			handler.onSuccess(service.getDocumentPatchs(neededPatchs));
		} catch (Exception e) {
			handler.onFailure(e);
		}
	}

	@Override
	public void onUserLeaveFromGroup(GroupIdentity result, String node,
			AsyncCallback<GroupIdentity> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onUserEnterToGroup(GroupIdentity result, String node,
			AsyncCallback<AccountGroup> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getGroupData(String id, AsyncCallback<GroupData> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void findGroup(String str, int offset, int limit,
			AsyncCallback<List<GroupProfile>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void whosOnline(String groupId, int offset, int limit,
			AsyncCallback<List<AccountIdentity>> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getGroupsByIds(List<String> ids, AsyncCallback<List<GroupProfile>> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addEnterRequest(String groupId, String accountId, String testAnsw, AsyncCallback<Boolean> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void processEnterRequest(String groupId, String accountId, AsyncCallback<Boolean> handler) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void createGroup(GroupData group, AsyncCallback<GroupData> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void enterToGroup(String groupId, String testAnswer, AsyncCallback<AccountGroup> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void leaveGroup(String groupId, AsyncCallback<Boolean> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void kickUserFromGroup(String groupId, String userId, AsyncCallback<Boolean> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateGroupProfile(GroupProfile groupProfile, AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updatePrintName(String groupId, String newName, AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getGroupTestQuestion(String groupId, AsyncCallback<String> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onNodesChange(List<NodeData> treeNode, String node,
			AsyncCallback<List<NodeData>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onNodesRemoved(List<NodeData> nodes, String node,
			AsyncCallback<List<NodeData>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getRootNodes(String groupId, AsyncCallback<List<NodeData>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getSubTree(String groupId, String parentNodeId, AsyncCallback<List<NodeData>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getSubTreeByPath(String groupId, String path, AsyncCallback<List<NodeData>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getSubTreeToPath(String groupId, String path, AsyncCallback<List<NodeData>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getNode(String nodeId, AsyncCallback<NodeData> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void saveNode(NodeData node, AsyncCallback<NodeData> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onNodesToTrash(List<String> nodeIds, String node,
			AsyncCallback<List<NodeData>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onNodesMoved(Pair<String, List<NodeData>> result, String node,
			AsyncCallback<Pair<String, List<NodeData>>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void checkNodeExisting(String nodeName, String groupNode, String parentNode,
			AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void moveNodes(String groupId, String newParentNode, List<String> nodeIds,
			AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void renameNode(String groupId, String nodeId, String newName,
			AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void putToTrash(String groupId, List<String> nodeIds, AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void removeNode(String groupId, List<String> nodeIds, AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateBoard(Board currentBoard, AsyncCallback<Void> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void findAccount(String str, int offset, int limit,
			AsyncCallback<List<AccountIdentity>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void attachGadgetToBoard(String boardId, Gadget g, AsyncCallback<Gadget> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void detachGadgetFromBoard(String boardId, String gadgetId,
			AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getRecentDocumentsCount(List<String> groupId, List<DocumentType> types,
			AsyncCallback<Integer> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void findDocument(String str, List<String> groupId, String authorId,
			List<DocumentType> type, int offset, int limit,
			AsyncCallback<List<DocumentData>> handler) {
		try {
			handler.onSuccess(service.findDocument(str, groupId, authorId, type, offset, limit));
		} catch (Exception e) {
			handler.onFailure(e);
		}	
	}

	@Override
	public void getDocuments(List<String> groupId, List<DocumentType> types, int offset, int limit,
			AsyncCallback<List<DocumentData>> handler) {
		try {
			handler.onSuccess(service.getDocuments(groupId, types, offset, limit));
		} catch (Exception e) {
			handler.onFailure(e);
		}		
	}

	@Override
	public void updateGadget(String boardId, Gadget g, AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getGroupMembers(String groupId, int offset, int limit,
			AsyncCallback<List<Pair<AccountIdentity, AccountGroup>>> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateGroupTestQuest(String id, String quest, String questAnswer,
			AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getEnterRequests(String groupId, int offset, int limit,
			AsyncCallback<List<GroupEnterRequest>> handler) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void applyRoleToUser(String roleId, String userId, String groupId,
			AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onUserRoleUpdated(Pair<Role, String> result, String node,
			AsyncCallback<Pair<Role, String>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setDefaultRole(String groupId, Role role, AsyncCallback<Void> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getAllGroup(int offset, int limit, AsyncCallback<List<GroupProfile>> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void sendFeedback(String userName, String message, AsyncCallback<Boolean> asyncCallback) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateCookieId(AsyncCallback<String> callback) {
		// TODO Auto-generated method stub
		
	}

}
